
#include <iostream>
#include <sys/eventfd.h>
#include <unistd.h>


void test_eventfd1()
{
    int efd = ::eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
    if (efd < 0)
    {
        perror("eventfd error");
        return;
    }
    uint64_t val = 1;
    ::write(efd, &val, sizeof val);
    ::write(efd, &val, sizeof val);
    ::write(efd, &val, sizeof val);
    ::write(efd, &val, sizeof val);
    // ::write(efd, &val, sizeof val);
    // ::write(efd, &val, sizeof val);

    uint64_t res = 0;
    ::read(efd, &res, sizeof res);
    std::cout << res << std::endl;

    res = 10;
    read(efd, &res, sizeof res);
    std::cout << res << std::endl;

    ::close(efd);
}


int main()
{
    test_eventfd1();
    return 0;
}

